logo

Overview of Spring Boot Starter Parent

Author: Shiva Krishna G

In this article, we will discuss how Spring Boot Starter Parent helps with managing dependency versions, the Java version used by the project, and the default configuration for plug-ins.

In this article, we will discuss spring-boot-starter-parent dependency with respect to the maven build tool.


Table of contents

What is the Spring Boot Starter Parent and How to use it?

All Spring Boot projects typically use spring-boot-starter-parent as the parent in pom.xml.

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>3.0.4</version>
</parent>

spring-boot-starter-parent allows us to manage the following things for multiple child projects and modules:

We should need to specify only the Spring Boot version number on this dependency. If you import additional starters, you can safely omit the version number.

logo

Parent Project Features

Maven users can inherit from the spring-boot-starter-parent project to obtain sensible defaults. The parent project provides the following features:

What is inside Spring Boot Starter Parent?

Spring Boot Starter Parent has spring-boot-dependencies as the parent pom. It inherits dependency management from spring-boot-dependencies.


<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-dependencies</artifactId>
    <version>3.0.4</version>
    <relativePath>../../spring-boot-dependencies</relativePath>
</parent>

For Spring Boot 3+ the default java version is 17. A few other settings related to encoding and source, target version are also set in the parent pom.

<properties>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>17</java.version>
    <resource.delimiter>@</resource.delimiter>
    <maven.compiler.source>${java.version}</maven.compiler.source>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.target>${java.version}</maven.compiler.target>
</properties>

Spring Boot Starter Parent specifies the default configuration for a host of plugins including maven-failsafe-plugin, maven-jar-plugin, maven-surefire-plugin, and maven-war-plugin etc.

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <parameters>true</parameters>
    </configuration>
</plugin>
<plugin>
    <artifactId>maven-failsafe-plugin</artifactId>
    <executions>
        <execution>
            <goals>
                <goal>integration-test</goal>
                <goal>verify</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <classesDirectory>${project.build.outputDirectory}</classesDirectory>
    </configuration>
</plugin>
<plugin>
    <artifactId>maven-jar-plugin</artifactId>
    <configuration>
        <archive>
            <manifest>
                <mainClass>${start-class}</mainClass>
                <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
            </manifest>
        </archive>
    </configuration>
</plugin>
<plugin>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>
        <archive>
            <manifest>
                <mainClass>${start-class}</mainClass>
                <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
            </manifest>
        </archive>
    </configuration>
</plugin> 

There are a few more plugins you can find them on spring-boot-starter-parent pom.xml


Using Spring Boot without the Parent POM

Not everyone likes inheriting from the spring-boot-starter-parent POM. You may have your own corporate standard parent that you need to use or you may prefer to explicitly declare all your Maven configurations.

If you do not want to use thespring-boot-starter-parent, you can still keep the benefit of the dependency management (but not the plugin management) by using ascope=import dependency, as follows:

<dependencyManagement>
    <dependencies>
        <dependency>
            <!-- Import dependency management from Spring Boot -->
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>2.1.0.BUILD-SNAPSHOT</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

The next step is we need to add an entry in the dependencyManagement of your project before the spring-boot-dependencies entry. For instance, to upgrade to another Spring Data release train, you could add the following element to your pom.xml:

<dependencyManagement>
    <dependencies>
        <!-- Override Spring Data release train provided by Spring Boot -->
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-releasetrain</artifactId>
            <version>Fowler-SR2</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>2.1.0.BUILD-SNAPSHOT</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

What does Spring Boot Starter Parent inherit from spring-boot dependencies?

Spring Boot Dependencies defines the default dependency management for all Spring Boot projects. If we would want to use a new version of a specific dependency, we can override the version by specifying a new property in the project pom. The below list shows some of the important dependencies that are managed by Spring Boot Dependencies parent pom. Since Spring Boot Starter Parent inherits from spring-boot dependencies, it shares all these characteristics as well.

<properties>
    <activemq.version>5.15.4</activemq.version>
    <antlr2.version>2.7.7</antlr2.version>
    <appengine-sdk.version>1.9.64</appengine-sdk.version>
    <artemis.version>2.4.0</artemis.version>
    <aspectj.version>1.8.13</aspectj.version>
    <assertj.version>3.9.1</assertj.version>
    <atomikos.version>4.0.6</atomikos.version>
    <bitronix.version>2.1.4</bitronix.version>
    <build-helper-maven-plugin.version>3.0.0</build-helper-maven-plugin.version>
    <byte-buddy.version>1.7.11</byte-buddy.version>
    <caffeine.version>2.6.2</caffeine.version>
    <cassandra-driver.version>3.4.0</cassandra-driver.version>
    <classmate.version>1.3.4</classmate.version>
    <commons-codec.version>1.11</commons-codec.version>
    <commons-dbcp2.version>2.2.0</commons-dbcp2.version>
    <commons-lang3.version>3.7</commons-lang3.version>
    <commons-pool.version>1.6</commons-pool.version>
    <commons-pool2.version>2.5.0</commons-pool2.version>
    <couchbase-cache-client.version>2.1.0</couchbase-cache-client.version>
    <couchbase-client.version>2.5.9</couchbase-client.version>
    <derby.version>10.14.1.0</derby.version>
    <dom4j.version>1.6.1</dom4j.version>
    <dropwizard-metrics.version>3.2.6</dropwizard-metrics.version>
    <ehcache.version>2.10.5</ehcache.version>
    <ehcache3.version>3.5.2</ehcache3.version>
    <elasticsearch.version>5.6.10</elasticsearch.version>
    <embedded-mongo.version>2.0.3</embedded-mongo.version>
    <exec-maven-plugin.version>1.5.0</exec-maven-plugin.version>
    <flatten-maven-plugin.version>1.0.1</flatten-maven-plugin.version>
    <flyway.version>5.0.7</flyway.version>
    <freemarker.version>2.3.28</freemarker.version>
    <git-commit-id-plugin.version>2.2.4</git-commit-id-plugin.version>
    <glassfish-el.version>3.0.0</glassfish-el.version>
    <groovy.version>2.4.15</groovy.version>
    <gson.version>2.8.5</gson.version>
    <h2.version>1.4.197</h2.version>
    <hamcrest.version>1.3</hamcrest.version>
    <hazelcast.version>3.9.4</hazelcast.version>
    <hazelcast-hibernate5.version>1.2.3</hazelcast-hibernate5.version>
    <hibernate.version>5.2.17.Final</hibernate.version>
    <hibernate-jpa-2.1-api.version>1.0.2.Final</hibernate-jpa-2.1-api.version>
    <hibernate-validator.version>6.0.11.Final</hibernate-validator.version>
    <hikaricp.version>2.7.9</hikaricp.version>
    <hsqldb.version>2.4.1</hsqldb.version>
    .......
</properties>

Find more default settings onspring-boot-dependencies pom.xml


Learn the latest release of Spring Boot on Spring Boot Tutorial

Reference

Spring Boot Project Pom.xml From GitHub
Spring Boot Dependencies pom.xml on GitHub


Related Spring and Spring Boot Tutorials/Guides: